package com.icoolkj.ms.api.rbac.feign;

import com.icoolkj.ms.api.rbac.dto.ClearUserPermissionsCacheDTO;
import com.icoolkj.ms.common.core.constant.Auth;
import com.icoolkj.ms.common.core.constant.ServiceNameConstants;
import com.icoolkj.ms.common.core.feign.FeignInsideAuthConfig;
import com.icoolkj.ms.common.core.response.ServerResponseEntity;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/02/04 20:20
 */
@FeignClient(value = ServiceNameConstants.RBAC_SERVICE, contextId = "permission")
public interface PermissionFeignClient {

    /**
     * 验证用户是否含有指定权限，必须全部拥有
     * @param permissions 权限码数组
     * @return 是否有权限
     */
    @GetMapping(value = Auth.CHECK_PERMI_AND)
    ServerResponseEntity<Boolean> checkPermiAnd(@RequestParam("userId") Long userId,
                                                @RequestParam("userType") String userType,
                                                @RequestParam String... permissions);

    /**
     * 验证用户是否含有指定权限，只需包含其中一个
     * @param permissions 权限码数组
     * @return 是否有权限
     */
    @GetMapping(value = Auth.CHECK_PERMI_OR)
    ServerResponseEntity<Boolean> checkPermiOr(@RequestParam("userId") Long userId,
                                               @RequestParam("userType") String userType,
                                               @RequestParam String... permissions);

    /**
     * 校验是否有某个uri的权限
     * @param userId
     * @param userType
     * @param uri
     * @param isAdmin
     * @param method
     * @return 是否有某个uri的权限
     */
    @GetMapping(value = Auth.CHECK_RBAC_URI)
    ServerResponseEntity<Boolean> checkPermission(@RequestParam("userId") Long userId,
                                                  @RequestParam("userType") String userType,
                                                  @RequestParam("uri") String uri,
                                                  @RequestParam("isAdmin") Integer isAdmin,
                                                  @RequestParam("method") Integer method);

    /**
     * 清除用户权限缓存
     * @param clearUserPermissionsCacheDTO
     * @return 是否调用成功
     */
    @PostMapping(value = FeignInsideAuthConfig.FEIGN_INSIDE_URL_PREFIX + "/insider/permission/clearUserPermissionsCache")
    ServerResponseEntity<Void> clearUserPermissionsCache(@RequestBody ClearUserPermissionsCacheDTO clearUserPermissionsCacheDTO);

    /**
     * 获取用户权限集合
     * @param userId
     * @param userType
     * @return
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_INSIDE_URL_PREFIX + "/insider/permission/getUserMenuPermissions")
    List<String> getUserMenuPermissions(@RequestParam("userId") Long userId, @RequestParam("userType") String userType);


    /**
     * 获取用户角色权限字符串集合
     * @param userId
     * @param userType
     * @return
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_INSIDE_URL_PREFIX + "/insider/permission/selectRoleKeyListByUserId")
    List<String> selectRoleKeyListByUserId(@RequestParam("userId") Long userId, @RequestParam("userType") String userType);



}
